from django.db import models
from django.contrib.auth.models import User

task_states =  (
      ('unscheduled', 'Unscheduled'),
      ('scheduled','Scheduled'),
      ('in_progress','In Progress'),
      ('complete','Complete'),
)


class Tag(models.Model):
    name = models.CharField(maxlength=100)
    def __str__(self):
        return '%s' % (self.name,)
    class Admin:
        pass

class Project(models.Model):
    title = models.CharField(maxlength=120)
    overview = models.TextField()
    request_date = models.DateField()
    start_date = models.DateField(blank=True, null=True)
    client = models.ForeignKey(User, related_name='client for projects')
    lead = models.ForeignKey(User, related_name='lead for projects')
    creator = models.ForeignKey(User, related_name='creator of this project')
    active = models.BooleanField()

    class Admin:
     list_display = ('title', 'client', 'lead', 'request_date', 'active')
     fields = (
        (None, {
            'fields': (('title', 'active'),
                       ('creator', 'client', 'lead'),
                       ('request_date', 'start_date'),
                       'overview')
        }),
        )
    def __str__(self):
        return '%s' % (self.title,)
    def get_absolute_url(self):
        return '/projects/%s/' % (self.id,)

class Objective(models.Model):
    label = models.CharField(maxlength=250)
    description = models.TextField()
    project = models.ForeignKey(Project)
    cost_estimate = models.CharField(maxlength=50, default="calculate task costs")
    status  = models.CharField(maxlength=100, choices=task_states, default="unscheduled")
    assigned = models.ForeignKey(User, null=True, blank=True)

    def __str__(self):
        return '%s' % (self.project.title + " :: " + self.label,)
    class Admin:
        fields = (
        (None, {
            'fields': (('label', 'project','status'), ('assigned', 'cost_estimate'), 'description')
        }),
        )

class Task(models.Model):
    label = models.CharField(maxlength=250)
    owner = models.ForeignKey(User)
    complete = models.BooleanField()
    bugfix = models.BooleanField()
    description = models.TextField(blank=True)
    project = models.ForeignKey(Project, null=True, blank=True)
    objective = models.ForeignKey(Objective, null=True, blank=True)
    created_date = models.DateField(auto_now_add=True, editable=False)
    days_to_complete = models.IntegerField(blank=True, null=True)

    class Admin:
        fields = (
        (None, {
            'fields': (('label', 'bugfix', 'complete',), ('owner', 'project', 'objective',), 'description')
        }),
        )
    def __str__(self):
        return '%s' % (self.label,)
#   def get_absolute_url(self):
#       return '/pm/accomplishment/%s' % (self.id,)
